import QtQuick 2.0
import com.ics.CppExample 1.0

Item {
    id: frmMain
    width: 800; height: 480
//    anchors.fill: parent
    // TODO: allow to define alignment of runable code element
    property bool leftAlign: true
    property int rightMargin: frmMain.width * 0.5
    property int leftMargin: 0.0
    property int fontSize: 18
    property string script: "import QtQuick 2.0\nRectangle {\n  color:\"blue\"\n  width: 100; height: 100\n} "

    // TODO: have a controller (or other flag) exported from the
    // 'printslides' app
    property variant preload: Controller

    Loader {
        id: ldlView
        anchors { top: parent.top; right: parent.right }
    }

    Dumper {
        id: utilWriter
    }

    TextEdit {
        id: txtDescription
        text: frmMain.script
        color: "#385661"
        font { pixelSize: frmMain.fontSize }
        anchors { left: frmMain.left; top: frmMain.top; right: parent.right;
            rightMargin: frmMain.rightMargin; leftMargin: frmMain.leftMargin
        }
    }

    Button {
        id: btnGo
        current: "imgs/play.png"; background: "imgs/play.png"
        pressed: "imgs/play_pressed.png"; focused: "imgs/play_pressed.png"
        anchors { top: txtDescription.bottom; left: frmMain.left }
        function saveLoad() {
            utilWriter.script = txtDescription.text
            utilWriter.write()
            ldlView.source = ""
            ldlView.source = "temp.qml"
        }

        onButtonClicked: btnGo.saveLoad()
    }

    Component.onCompleted: {
        if (frmMain.preload != undefined) {
           btnGo.saveLoad()
        } else {
           console.log("### No controller found.")
        }
    }
}
